<div class="filter">
</div>
<table class="tablesorter" id="tab1">
	<thead>
		<tr>
			<th class="col_date">Date<span class="close">X</span></th>
			<th class="col_site">Site<span class="close">X</span></th>
			<?php if(isset($displayCols[2])):?>
			<th class="col_publisher">Publisher<span class="close">X</span></th>
			<?php endif;?>
			<?php if(isset($displayCols[3])):?>
			<th class="col_placement">Placement<span class="close">X</span></th>
			<?php endif;?>
			<?php if(isset($displayCols[4])):?>
			<th class="col_campaign">Campaign<span class="close">X</span></th>
			<?php endif;?>
			<th class="col_partner">Partner<span class="close">X</span></th>
			<th class="col_successed">Successed<span class="close">X</span></th>
		</tr>
	</thead>
	<tbody>
	<?php if((!empty($reportItems)) && $reporttype=="8"): ?>
	<?php foreach ($reportItems as $k=>$reportItem):
			$date['start'] = $reportItem['date'];
			if($interval == 2){
				list($year, $week) = str_split($k, 4);
				$date = Util::getStartAndEndDate($week, $year);
			}
	?>
		<tr>
			<td class="col_date"><?php echo $date['start'];?> <?php if($interval==2){ echo '---'.$date['end'];} ?></td>
			<td class="col_domain"><?php echo isset($reportItem['domain'])? $reportItem['domain'] : ''; ?></td>
			<?php if(isset($displayCols[2])): ?>
				<td class="col_publisher"><?php echo $reportItem['pub'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[3])): ?>
				<td class="col_placement"><?php echo $reportItem['pla'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[4])): ?>
				<td class="col_campaign"><?php echo $reportItem['cam'];?></td>
			<?php endif; ?>
			<td class="col_partner"><?php echo isset($reportItem['partner'])? $reportItem['partner'] : ''; ?></td>
			<td class="col_successed"><?php echo isset($reportItem['successed'])? $reportItem['successed'] : 0; ?></td>
		</tr>
	<?php endforeach;?>
	<?php endif;?>
	</tbody>
</table>

<script type="text/javascript" src="<?php echo JS_DIR; ?>jquery.tablesorter.js"></script>
<script type="text/javascript" src="<?php echo JS_DIR; ?>jquery.uitablefilter.js"></script>
<script type="text/javascript">
	var $table = $('#tab1');
	$table.tablesorter({sortList: [[0,0]]});

	$('#ad_filter').click(function(){
		var id_to_header={
						  "ad_sites":"Site"
					   	 };
		
		var $table = $('#tab1');
		var filters = new Array();
	    var elems = $('.filters_col');
	    elems.each(function(){
			var elem = $(this);
			if(elem.css('display') != 'none'){
				if(elem.val() != ""){
					filters[elem.val()] = id_to_header[elem.attr('id')];
				}
			}
		});
		console.log(filters);
	    $.uiTableFilter( $table, filters);
	});
	
</script>
